#include <iostream>
using namespace std;


void check_state(void){
    cout<<"fail"<<cin.fail()
        <<"good"<<cin.good()
        <<"efo"<<cin.eof()
        <<"bad"<<cin.bad()<<endl;
}
void test(){
    cout<<"第一次输入"<<endl;
    int num;
    cin>>num;
    cout<<num<<endl;
    cout<<"第二次输入（错误）"<<endl;
    while(1){
    cin>>num;
    check_state();
    if(cin.fail()==1){
    cin.clear();
    cin.ignore(1024,'\n');
    }else{
        break;
    }
    }
    cout<<num<<endl;
    cout<<"第三次输入"<<endl;
    cin>>num;
    cout<<num<<endl;
}

int main(int argc, char * argv[]){
    test();
    return 0;
}

